import request from "@/utils/request"
import { getUserAll } from "./user"

/**
 *  添加课程  
 *  post   json-server (post) (get)  get
 *  @params
 *    name 课程名字
 *    price 课程价格
 *    desc  课程描述
 *    teacher 课程老师  
 *    time  课程时间
 *    type  1 HTML    seleted ---  /......../
 *    create_at :发布时间,  时间插件
 *    cover_img 视频封面, upload
 *    sale  折扣        
 *     is_hot 热推     switch   
 *     author  发布者
 *    views  浏览次数   
 *    
 *    isZan  点赞     swtich
 *   
 */

 //添加课程
export const addClass = async (params) => request.post("/classes",params)


//获取课程

export const getClass = async () => request.get("/classes")

//修改课程信息

//删除课程 delelte

export async function del(id){
    return await request({
       url:"/classes/"+id,
       method:"delete"
    })
  }

//搜索课程 
// 按照type搜索

export const searchByType = async (type) => request.get("/classes?type="+type)

// 按照name模糊搜索
export const searchByName = async (type,keywords) =>{
        //分类
       let res = await searchByType(type);
       console.log(keywords)
       // 获取指定分类的所有数据
       return {
           code:200,
           msg:"查询成功",
           data:res.data.filter(item=>item.name.includes(keywords))
       }
}







                                             